package com.sw.bbs.board.controller;

import com.sw.bbs.board.service.ProfileOperaService;
import com.sw.bbs.board.vo.request.board.OperaBoardRequest;
import com.sw.bbs.board.vo.request.comment.OperaCommentRequest;
import com.sw.bbs.board.vo.request.post.OperaPostRequest;
import com.sw.bbs.common.common.GlobalException;
import com.sw.bbs.user.dao.ReportMapper;
import com.sw.bbs.user.pojo.Report;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
@Api(value = "用户操作模块",description = "用户操作", tags = {"User Opera Module"})
@RestController("/profileOpera/")
@Slf4j
public class ProfileOperaController {
    
    @Autowired
    private ProfileOperaService userOperaService;

    @Autowired
    private ReportMapper reportMapper;

    @GetMapping("/operaBoard")
    @ApiOperation(value = "用户操作板块接口", response = ResponseEntity.class)
    @ApiResponses({@ApiResponse(code = 200, message = "结果结构", response = ResponseEntity.class)})
    public ResponseEntity<?> operaBoard(OperaBoardRequest request, HttpServletRequest httpServletRequest)
            throws GlobalException {
        try {
            Integer result =  userOperaService.operaBoard(request, httpServletRequest);
            return new ResponseEntity<>(result, HttpStatus.OK);
        } catch (Exception e) {
            log.error("operaBoard", e);
            throw new GlobalException("/userOpera/operaBoard", e.getMessage());
        }
    }

    @GetMapping("/operaPost")
    @ApiOperation(value = "用户操作帖子接口", response = ResponseEntity.class)
    @ApiResponses({@ApiResponse(code = 200, message = "结果结构", response = ResponseEntity.class)})
    public ResponseEntity<?> operaPost(OperaPostRequest request, HttpServletRequest httpServletRequest)
            throws GlobalException {
        try {
            Integer result =  userOperaService.operaPost(request, httpServletRequest);
            return new ResponseEntity<>(result, HttpStatus.OK);
        } catch (Exception e) {
            log.error("operaPost", e);
            throw new GlobalException("/userOpera/operaPost", e.getMessage());
        }
    }

    @GetMapping("/operaComment")
    @ApiOperation(value = "用户操作评论接口", response = ResponseEntity.class)
    @ApiResponses({@ApiResponse(code = 200, message = "结果结构", response = ResponseEntity.class)})
    public ResponseEntity<?> operaComment(OperaCommentRequest request, HttpServletRequest httpServletRequest)
            throws GlobalException {
        try {
            Integer result =  userOperaService.operaComment(request, httpServletRequest);
            return new ResponseEntity<>(result, HttpStatus.OK);
        } catch (Exception e) {
            log.error("operaComment", e);
            throw new GlobalException("/userOpera/operaComment", e.getMessage());
        }
    }


    @PostMapping("/addReport")
    @ApiOperation(value = "增加举报接口",response = ResponseEntity.class)
    @ApiResponses({@ApiResponse(code = 201, message = "插入帖子评论", response = ResponseEntity.class)})
    public ResponseEntity<?> addReport(@ApiParam @ModelAttribute Report record)
            throws GlobalException {
        try {
            Integer result = reportMapper.insert(record);
            return new ResponseEntity<>(result, HttpStatus.OK);
        } catch (Exception e) {
            log.error("addReport", e);
            throw new GlobalException("/common/addReport", e.getMessage());
        }
    }

}
